home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / lib / python2.6 / dist-packages / Onboard / KeyCommon.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2009-04-20  |  8.0 KB  |  214 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. from math import sqrt
  5. BASE_PANE_TAB_HEIGHT = 40
  6. (CHAR_ACTION, KEYSYM_ACTION, KEYCODE_ACTION, MODIFIER_ACTION, MACRO_ACTION, SCRIPT_ACTION) = range(1, 7)
  7.  
  8. class KeyCommon:
  9.     ''' a library-independent key class. Specific 
  10.         rendering options are stored elsewhere. '''
  11.     action_type = None
  12.     action = None
  13.     pane = None
  14.     on = False
  15.     stuckOn = False
  16.     sticky = False
  17.     beingScanned = False
  18.     
  19.     def __init__(self, pane):
  20.         self.pane = pane
  21.  
  22.     
  23.     def setProperties(self, action_type, action, labels, sticky, fontOffsetX, fontOffsetY):
  24.         self.fontOffsetX = fontOffsetX
  25.         self.fontOffsetY = fontOffsetY
  26.         self.action = action
  27.         self.action_type = action_type
  28.         self.sticky = sticky
  29.         self.labels = labels
  30.  
  31.     
  32.     def paintFont(self, xScale, yScale, x, y, context = None):
  33.         ''' Key.paintFont() paints a font. All context-related
  34.             actions are UI-dependent. Thus, they are moved 
  35.             to overriddable classes.'''
  36.         if hasattr(self, 'labels'):
  37.             if xScale < yScale:
  38.                 self.fontScale = xScale
  39.             else:
  40.                 self.fontScale = yScale
  41.             if self.pane.keyboard.mods[1]:
  42.                 if self.pane.keyboard.mods[128] and self.labels[4]:
  43.                     label = self.labels[4]
  44.                 elif self.labels[2]:
  45.                     label = self.labels[2]
  46.                 elif self.labels[1]:
  47.                     label = self.labels[1]
  48.                 else:
  49.                     label = self.labels[0]
  50.             elif self.pane.keyboard.mods[128] and self.labels[4]:
  51.                 label = self.labels[3]
  52.             elif self.pane.keyboard.mods[2]:
  53.                 if self.labels[1]:
  54.                     label = self.labels[1]
  55.                 else:
  56.                     label = self.labels[0]
  57.             else:
  58.                 label = self.labels[0]
  59.             if len(label) > 4:
  60.                 self.fontScale -= 1.1
  61.             elif len(label) > 1:
  62.                 self.fontScale -= 1.1
  63.             
  64.             if self.fontScale < 0.5:
  65.                 self.fontScale = 0.5
  66.             
  67.             self.moveObject((x + self.fontOffsetX) * xScale + 4, (y + self.fontOffsetY) * yScale - 0.03 * self.pane.fontSize * sqrt(self.fontScale), context)
  68.             self.createLayout(label)
  69.         
  70.  
  71.  
  72.  
  73. class TabKeyCommon(KeyCommon):
  74.     ''' class for those tabs up the right hand side '''
  75.     
  76.     def __init__(self, keyboard, width, pane):
  77.         KeyCommon.__init__(self, pane)
  78.         self.width = width
  79.         self.keyboard = keyboard
  80.         self.modifier = None
  81.         self.sticky = True
  82.  
  83.     
  84.     def pointWithinKey(self, widget, mouseX, mouseY):
  85.         ''' does exactly what the name says - checks for the 
  86.             mouse within a key. returns bool. '''
  87.         if mouseX > self.keyboard.kbwidth and mouseY > self.height * self.index + BASE_PANE_TAB_HEIGHT and mouseY < self.height * (self.index + 1) + BASE_PANE_TAB_HEIGHT:
  88.             return True
  89.         return False
  90.  
  91.     
  92.     def paint(self, context = None):
  93.         ''' paints the TabKey object '''
  94.         self.height = self.keyboard.height / len(self.keyboard.panes) - BASE_PANE_TAB_HEIGHT / len(self.keyboard.panes)
  95.         self.index = self.keyboard.panes.index(self.pane)
  96.  
  97.  
  98.  
  99. class BaseTabKeyCommon(KeyCommon):
  100.     ''' class for the tab that brings you to the base pane '''
  101.     
  102.     def __init__(self, keyboard, width):
  103.         KeyCommon.__init__(self, None)
  104.         self.width = width
  105.         self.keyboard = keyboard
  106.         self.modifier = None
  107.         self.sticky = False
  108.  
  109.     
  110.     def pointWithinKey(self, widget, mouseX, mouseY):
  111.         if mouseX > self.keyboard.kbwidth and mouseY < BASE_PANE_TAB_HEIGHT:
  112.             return True
  113.         return False
  114.  
  115.     
  116.     def paint(self, context = None):
  117.         """Don't draw anything for this key"""
  118.         pass
  119.  
  120.  
  121.  
  122. class LineKeyCommon(KeyCommon):
  123.     ''' class for keyboard buttons made of lines '''
  124.     
  125.     def __init__(self, pane, coordList, fontCoord, rgba):
  126.         KeyCommon.__init__(self, pane)
  127.         self.coordList = coordList
  128.         self.fontCoord = fontCoord
  129.         self.rgba = rgba
  130.  
  131.     
  132.     def pointCrossesEdge(self, x, y, xp1, yp1, sMouseX, sMouseY):
  133.         ''' Checks whether a point, when scanning from top left crosses edge'''
  134.         if (y <= sMouseY or sMouseY < yp1 or yp1 <= sMouseY) and sMouseY < y:
  135.             pass
  136.         return sMouseX < (xp1 - x) * (sMouseY - y) / (yp1 - y) + x
  137.  
  138.     
  139.     def pointWithinKey(self, widget, mouseX, mouseY):
  140.         '''Checks whether point is within shape.
  141.            Currently does not bother trying to work out
  142.            curved paths accurately. '''
  143.         x = self.coordList[0]
  144.         y = self.coordList[1]
  145.         c = 2
  146.         coordLen = len(self.coordList)
  147.         within = False
  148.         sMouseX = mouseX / self.pane.xScale
  149.         sMouseY = mouseY / self.pane.yScale
  150.         while not c == coordLen:
  151.             xp1 = self.coordList[c + 1]
  152.             yp1 = self.coordList[c + 2]
  153.             
  154.             try:
  155.                 if self.coordList[c] == 'L':
  156.                     within = self.pointCrossesEdge(x, y, xp1, yp1, sMouseX, sMouseY) ^ within
  157.                     c += 3
  158.                     x = xp1
  159.                     y = yp1
  160.                 else:
  161.                     xp2 = self.coordList[c + 3]
  162.                     yp2 = self.coordList[c + 4]
  163.                     xp3 = self.coordList[c + 5]
  164.                     yp3 = self.coordList[c + 6]
  165.                     within = self.pointCrossesEdge(x, y, xp3, yp3, sMouseX, sMouseY) ^ within
  166.                     x = xp3
  167.                     y = yp3
  168.                     c += 7
  169.             continue
  170.             except ZeroDivisionError:
  171.                 strerror = None
  172.                 print strerror
  173.                 print 'x: %f, y: %f, yp1: %f' % (x, y, yp1)
  174.                 continue
  175.             
  176.  
  177.             None<EXCEPTION MATCH>ZeroDivisionError
  178.         return within
  179.  
  180.     
  181.     def paint(self, xScale, yScale, context = None):
  182.         ''' This class is quite hard to abstract, so all of its
  183.             processing lies now in the UI-dependent class.\xc2\xa0'''
  184.         pass
  185.  
  186.     
  187.     def paintFont(self, xScale, yScale, context = None):
  188.         KeyCommon.paintFont(self, xScale, yScale, self.coordList[0], self.coordList[1], context)
  189.  
  190.  
  191.  
  192. class RectKeyCommon(KeyCommon):
  193.     ''' An abstract class for rectangular keyboard buttons '''
  194.     
  195.     def __init__(self, pane, x, y, width, height, rgba):
  196.         KeyCommon.__init__(self, pane)
  197.         self.x = x
  198.         self.y = y
  199.         self.width = width
  200.         self.height = height
  201.         self.rgba = rgba
  202.  
  203.     
  204.     def pointWithinKey(self, widget, mouseX, mouseY):
  205.         if mouseX / self.pane.xScale > self.x and mouseX / self.pane.xScale < self.x + self.width and mouseY / self.pane.yScale > self.y and mouseY / self.pane.yScale < self.y + self.height:
  206.             return True
  207.         return False
  208.  
  209.     
  210.     def paint(self, xScale, yScale, context = None):
  211.         pass
  212.  
  213.  
  214.